package com.lzrj;

import com.beust.jcommander.JCommander;
import com.lzrj.server.CmdArgOption;
import com.lzrj.server.ProcessInfo;
import com.lzrj.server.WebServer;

import java.util.List;

public class Application {

    public static void main(String[] args) {
        // --webapp=a --server.port=8080 --context=1

        CmdArgOption cmdArgOption = new CmdArgOption();

        JCommander commander = JCommander.newBuilder().addObject(cmdArgOption).build();
        commander.parse(args);

        if (cmdArgOption.isHelp()){
            commander.setProgramName("x-webserver");
            commander.usage();
            return;
        }

        if (cmdArgOption.getPkillPort() != null){
            ProcessInfo.killWebPortProcessId(cmdArgOption.getPkillPort());
            return;
        }
        List<String> webapp = cmdArgOption.getWebapp();

        if (webapp == null || webapp.size() == 0){
            System.out.println("fail,未指定项目路径参数-w或--webapp");
            return;
        }
        WebServer.start(cmdArgOption);
    }

}
